<template>
  <!-- 我的勋章 -->
  <div class="medal">
    <MyHead title="我的勋章墙"></MyHead>
    <div class="top-box">
      <div class="top">
        <div class="title">我的勋章墙</div>
        <div class="medal-length">已累计获<span style="font-weight: bold; font-size: 18px;">{{ this.medalinfo.length }}</span>得枚勋章</div>
      </div>
      <div class="badge-box">
        <img
          src="../../assets/images/ico-xz03.png"
          alt=""
          width="100%"
          height="100%"
        />
      </div>
    </div>
    <div class="content-box">
      <div class="item-box" v-for="(item, index) in medalinfo" :key="index" @click="goDetails(item)">
        <div class="img-box">
          <img
            v-if="item.medal_image"
            :src="sourceURL + item.medal_image"
            alt=""
            srcset=""
            class="img"
          />
          <van-image width="100%" v-else>
            <template v-slot:error></template>
          </van-image>
        </div>
        <div class="text-style">{{ item.act_title }}</div>
        <div class="text-style">{{ item.createtime_text }}</div>
      </div>
    </div>
    <MyTab></MyTab>
  </div>
</template>

<script>
export default {
  data() {
    return {
      openid: $.cookie("openid"),
      medalinfo: [], //勋章信息
    };
  },
  computed: {},
  methods: {
    /*勋章列表*/
    async medealList() {
      let res = await this.$ajax.medealList({
        openid: this.openid,
        limits:99,
      });
      if (res.code == 1) {
        this.medalinfo = res.data;
      } else {
        this.$toast(res.msg);
      }
    },
    /*详情*/
    goDetails(item){
      this.$router.push({name:"medalDetails",query:{act_title:item.act_title,createtime_text:item.createtime_text,medal_image:item.medal_image}});
    } ,
  },
  mounted() {
    this.medealList();
  },
};
</script>

<style lang="scss" scoped>

// 居中（上下左右居中）
.text-style {
  display: flex;
  justify-content: center;
  align-items: center;
}

.medal {
  width: 100%;
  min-height: 100vh;
  height: 100%;
  background-color: #f9f9f9;

  .top-box {
    position: relative;
    .top {
      border: 1px solid;
      line-height: 30px;
      padding: 20px;
      background: linear-gradient(to right, #f44336 50%, #b71c1c);
      color: white;

      .title {
        font-size: 18px;
        font-family: SourceHanSansSC-regular;
      }

      .medal-length {
        font-size: 14px;
        font-family: SourceHanSansSC-regular;
      }
    }
    .badge-box {
      margin-left: 100px;
      width: 100px;
      height: 100px;
      position: absolute;
      top: 40px;
      right: 60px;
    }
  }

  .content-box {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    margin-top: 40px;
    line-height: 20px; 

    .item-box {
      background: white;
      border-radius: 10px;
      padding: 5px;
      margin-top: 10px;
      width: 30%;
      .img-box {
        max-width: 100%;
        height: 100px;
        box-sizing: content-box;
        display: flex;
        justify-content: center;
        align-content: center;
        overflow: hidden;
        /* 隐藏超出容器的部分 */
        position: relative;
        margin-bottom: 10px;
        img {
          width: 108px;
          height: 100px;
          background: red;
        }
      }
    }
  }
}
</style>